<template>
	<view>
		<input class="uni-input" type="text" value="" v-model="oldPassword" placeholder="输入旧密码"/>
		<input class="uni-input" type="text" value="" v-model="newPassword" placeholder="输入新密码"/>
		<input class="uni-input" type="text" value="" v-model="reNewPassword" placeholder="输入确认密码"/>
		<view class="py-2 px-3">
			<button class="bg-main text-white" style="border-radius: 50rpx; border: 0;" type="primary" @click="submit" :disabled="disabled">设置</button>
		</view>
	</view>
</template>

<script>
	 import { mapState } from 'vuex';
	export default {
		data() {
			return {
				oldPassword:'',
				newPassword:'',
				reNewPassword:''
			}
		},
		computed:{
			disabled(){
				return this.oldPassword == '' || this.newPassword == '' ||this.reNewPassword == ''
			},
			...mapState({
				loginStatus:state=>state.loginStatus
			})
		},
		methods: {
			checked(){
				if(this.reNewPassword !== this.newPassword)
				{
					uni.showToast({
						title:'两次密码不一致',
						icon:'none'
					});
					return false
				}
				return true
			},
			submit(){
				if(!this.checked()){
					return ;
				}
				if(this.loginStatus)
				{
					
					this.$R.put("/system/user/updatePwd",{password:this.reNewPassword}).then(res=>{
						if(res.code ==200){
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
							this.$store.commit("logout");
							uni.navigateTo({
								url:'../login/login'
							})
						}
					})
				}
			}
		}
	}
</script>

<style>

</style>
